let app =new Vue({
    el:'#app',
    data:{
        user:JSON.parse(sessionStorage.getItem('user')),
        unreadNum:sessionStorage.getItem("unreadNum"),
        examPaperResult:[],
        searchPaperType:null,
        searchSubjectName:null,
        startNum:0,
        endNum:10,
        currPage:1,     //当前页
        pageSum:null    //总页数
    },
    created(){
        $.ajax({
            url:'http://localhost:8080/examPaperResult/select',
            type:'get',
            data:{createUser:this.user.userId,levelName:this.user.levelName},
            success:function(vo){
                if(vo.code==200){
                    app.examPaperResult=vo.data;
                    //总页数
                    app.pageSum=vo.data.length%10==0 ? Math.floor(vo.data.length/10) : Math.floor(vo.data.length/10)+1 ;
                }
            }
        });
        
    },
    methods: {
        choose: function (event) {
            // 获取当前点击对象（a 节点）
            let span = event.currentTarget;
            //先把其他节点的样式还原
            $(span).siblings().find("a").removeClass("title_paper_2");
            //改变当前节点的样式
            $(span).find("a").addClass("title_paper_2");

            let str=$(span).find("a").text();

            if(str=='固定试卷'){
                this.searchPaperType=1;
            }else if(str=='时段试卷'){
                this.searchPaperType=2;
            }else if(str=='班级试卷'){
                this.searchPaperType=3;
            }else{
                this.searchPaperType=null;
            }

            $.ajax({
                url:'http://localhost:8080/examPaperResult/select',
                type:'get',
                data:{createUser:this.user.userId,levelName:this.user.levelName,paperType:this.searchPaperType,subjectName:this.searchSubjectName},
                success:function(vo){
                    if(vo.code==200){
                        app.examPaperResult=vo.data;
                        // 重置分页
                        app.startNum=0;
                        app.endNum=10;
                        app.currPage=1;
                        //总页数
                        app.pageSum=vo.data.length%10==0 ? Math.floor(vo.data.length/10) : Math.floor(vo.data.length/10)+1 ;
                        $(".btn-next").removeClass("disabled");
                        $(".btn-prev").addClass("disabled");
                        if(app.pageSum==1){
                            $(".btn-next").addClass("disabled");
                        }
                    }
                }
            });

        },
        choose2: function (event) {
            // 获取当前点击对象（a 节点）
            let span = event.currentTarget;
            //先把其他节点的样式还原
            $(span).siblings().find("a").removeClass("title_paper_2");
            //改变当前节点的样式
            $(span).find("a").addClass("title_paper_2");

            let str=$(span).find("a").text();

            if(str=='全部'){
                this.searchSubjectName=null;
            }else{
                this.searchSubjectName=str;
            }

            $.ajax({
                url:'http://localhost:8080/examPaperResult/select',
                type:'get',
                data:{createUser:this.user.userId,levelName:this.user.levelName,paperType:this.searchPaperType,subjectName:this.searchSubjectName},
                success:function(vo){
                    if(vo.code==200){
                        app.examPaperResult=vo.data;
                        // 重置分页
                        app.startNum=0;
                        app.endNum=10;
                        app.currPage=1;
                        //总页数
                        app.pageSum=vo.data.length%10==0 ? Math.floor(vo.data.length/10) : Math.floor(vo.data.length/10)+1 ;
                        $(".btn-next").removeClass("disabled");
                        $(".btn-prev").addClass("disabled");
                        if(app.pageSum==1){
                            $(".btn-next").addClass("disabled");
                        }
                    }
                }
            });

        },
        lookPaper:function(index){
            sessionStorage.setItem("examPaperResultView",JSON.stringify(app.examPaperResult[index]));
            window.open("paper_view.html");
            
        },
        analyse:function(examPaperResult){
            sessionStorage.setItem("examPaperResultAnalyse",JSON.stringify(examPaperResult));
            window.open("exam_analyse.html");
        },
        //上一页
        up:function(){
            if(this.currPage==1){
                return;
            }
            if(this.currPage<=this.pageSum){
                $(".btn-next").removeClass("disabled");
            }
            this.startNum=this.startNum-10;
            this.endNum=this.endNum-10;
            this.currPage=this.currPage-1;

            if(this.currPage==1){
                $(".btn-prev").addClass("disabled");
            }
        },
        //下一页
        down:function(){
            if(this.currPage==this.pageSum){
                return;
            }
            if(this.currPage>=1){
                $(".btn-prev").removeClass("disabled");
            }
            this.startNum=this.startNum+10;
            this.endNum=this.endNum+10;
            this.currPage=this.currPage+1;
            if(this.currPage==this.pageSum){
                $(".btn-next").addClass("disabled");
            }
        }
    }
});